package cn.edu.scau.cmi.zhengweibo.client.controller;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.TextField;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.edu.scau.cmi.zhengweibo.client.spring.SpringApplicationContextClient;
import cn.edu.scau.cmi.zhengweibo.comprehension.dao.StudentDAO;
import cn.edu.scau.cmi.zhengweibo.comprehension.dao.TeacherDAO;
import javafx.event.ActionEvent;

import javafx.scene.control.TextArea;

public class Spring_HibernateViewController {
	@FXML
	private TextField tf;
	@FXML
	private Button btn1;
	@FXML
	private TextArea textarea;

	ApplicationContext applicationContext = new SpringApplicationContextClient().getApplicationContext();
	StudentDAO studentDao = (StudentDAO) applicationContext.getBean("StudentDAO");
	TeacherDAO teacherDAO = (TeacherDAO)applicationContext.getBean("TeacherDAO");
	long id;
	
	@FXML
	public void find(ActionEvent event) {
		id = Long.parseLong(tf.getText());
		textarea.appendText("学号为"+id+"的学生姓名为："+studentDao.findById(id).getName()+" 指导老师为："+studentDao.findById(id).getTeacher().getName()+'\n');
	}
}
